package net.jjjshop.common.mapper.user;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.jjjshop.common.entity.lbt.JybBusinessOrderEntity;
import net.jjjshop.common.entity.lbt.UserBillEntityRequest;
import net.jjjshop.common.entity.user.UserBill;
import net.jjjshop.common.entity.user.UserBillResponse;
import net.jjjshop.common.entity.user.UserDedicateRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 用户账单表 Mapper 接口
 */
public interface UserBillMapper extends BaseMapper<UserBill> {

    List<UserBillResponse> fundMonitoring(Map<String, Object> map);

    @Select("SELECT SUM(number) from eb_user_bill WHERE pm = 1 and category ='INTEGRAL_TYPE' and uid =#{uid }")
     Double getTzTotal(Integer uid);


    /**
     * 查询用户扶持次数
     * @param uid
     * @return
     */
    @Select("SELECT COUNT(*) from eb_user_bill WHERE pm = 1 and category ='COMMISSION_TYPE' and mark ='201' and uid =#{uid }")
    Integer selectUserHelpNum(Integer uid);

    IPage<UserBillEntityRequest> userBillList(Page<UserBillEntityRequest> pageUser,@Param("status") Integer status,@Param("uid") Integer uid,@Param("pmtype") Integer pmtype,
                                              @Param("phone") String phone,@Param("nickname") String nickname,@Param("title") String title,@Param("type") String type);


    /**
     * 查询基金捐赠记录
     * @return
     */
    @Select("SELECT a.number,b.nickName name,b.mobile,a.create_time from jjjshop_user_bill a LEFT JOIN jjjshop_user b ON a.uid = b.user_id\n" +
            "WHERE a.title='爱心基金捐赠' and a.pm=0 ORDER BY a.create_time desc")
    List<UserDedicateRecord> getUserDedicateRecord();
}
